import { useTheme } from "vuetify";
import { computed } from "vue";

export function getLocalDark() {
  return localStorage.getItem("dark") === "true";
}
export function setLocalDark(dark: boolean) {
  localStorage.setItem("dark", dark.toString());
}

export default function () {
  const theme = useTheme();
  const isDark = computed(() => theme.global.current.value.dark);
  const changeTheme = () => {
    theme.global.name.value = isDark.value ? "defaultCustomTheme" : "defaultCustomDarkTheme";
    setLocalDark(isDark.value);
  };

  return {
    changeTheme,
    isDark,
    theme,
  };
}
